package com.example.demo.service.Impl;

import com.example.demo.dao.IThmana;
import com.example.demo.model.Thmana;
import com.example.demo.service.IThmanaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

;

/**
 * @author Administrator 张少婷
 */

@Service
public class ThmanaServiceImpl implements IThmanaService {

    @Autowired
    private IThmana thmanaMapper;
    @Override
    public int insertThmana(Thmana thmana){
        int thmanaValue=0;

        Thmana thmana1=new Thmana();
        thmana1.setLbid(thmana.getLbid());
        List<Thmana> getT=thmanaMapper.getAllThmana(thmana1);
        if(getT.size()>0){
            thmanaValue=-1;

        }else{
            thmanaValue=thmanaMapper.insertThmana(thmana);
        }

        return thmanaValue;
    }

    @Override
    public List<Thmana> getAllThmana(Thmana thmana) {


        return thmanaMapper.getAllThmana(thmana);
    }

    @Override
    public int updateThmana(Thmana thmana) {
        int thmanaValues=0;
        if(thmana.getLbid()!=0){
            thmanaValues=thmanaMapper.updateThmana(thmana);
        }
        return thmanaValues;
    }

    @Override
    public int deleteThmana(Thmana thmana) {
        int thmanaValues=0;
        if(thmana.getLbid()!=0)
        {
            //主键是否与其他表有关联

            thmanaValues=thmanaMapper.deleteThmana(thmana);
        }
        return thmanaValues;
    }

    @Override
    public Thmana getThmana(Thmana thmana) {
        Thmana thmana1=new Thmana();
        if(thmana.getLbid()!=0){
            thmana1=thmanaMapper.getThmana(thmana);
        }
        return thmana1;
    }

}
